package game.JFrame;

import javax.swing.*;

public class JFrameDemo {

    public static void main(String[] args) {
        JFrame frame = new JFrame("这是我的第一个Frame");
        frame.setSize(400, 300);
        frame.setLocation(200, 200);
        frame.setVisible(true);
        // 设置关闭窗口时退出程序
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 设置窗口大小不可变
        frame.setResizable(false);
        // 设置窗口居中
        frame.setLocationRelativeTo(null);

        // 设置窗口图标
        ImageIcon icon = new ImageIcon("src/main/resources/images/icon.png");
        frame.setIconImage(icon.getImage());

        //JDialog
        JDialog dialog = new JDialog(frame, "这是第一个对话框", true);
        dialog.setSize(300, 200);
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        dialog.setResizable(false);
        dialog.setIconImage(icon.getImage());

        //JPanel
        JPanel panel = new JPanel();
        panel.setBounds(0, 0, 300, 200);
        panel.setLayout(null);
        panel.setBackground(new java.awt.Color(0, 0, 0));
        dialog.add(panel);

        JButton okButton = new JButton("确定");
        okButton.setBounds(100, 100, 100, 50);
        okButton.addActionListener(e -> {
            System.out.println("点击了确定按钮");
            dialog.dispose();
        });
        panel.add(okButton);


    }
}
